
#include "zklog/zklog_wrapper.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/basic_file_sink.h"

zk::log::log_wrapper::sink_ptr zk::log::log_wrapper::make_colored_console_sink(
    const std::string& pattern,
    zk::log::log_wrapper::level_t filter_level)
{
    auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    console_sink->set_level(filter_level);
    //console_sink->set_pattern("%L | %Y-%m-%d %X.%f | %t | %^%v%$");
    console_sink->set_pattern(pattern);
    return console_sink;
}

zk::log::log_wrapper::sink_ptr zk::log::log_wrapper::make_daily_file_sink(
    const filename_t& filepath,
    const std::string& pattern,
    level_t filter_level /*= info*/,
    uint16_t max_files /*= 30*/,
    int rotation_hour/*=23*/,
    int rotation_minute/*=59*/,
    bool truncate /*= false*/)
{
    auto file_sink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(filepath, rotation_hour, rotation_minute, truncate, max_files);
    file_sink->set_level(filter_level);
    file_sink->set_pattern(pattern);
    //file_sink->set_pattern("%8l | %Y-%m-%d %X.%f | %t | %s:%# | %v");
    return file_sink;
}

zk::log::log_wrapper::logger_ptr zk::log::log_wrapper::make_multisink_logger(
    const std::string& logger_name,
    spdlog::sinks_init_list sinks,
    level_t filter_level /*= info*/)
{
    auto logger = std::make_shared<spdlog::logger>(logger_name, sinks);
    logger->set_level(filter_level);
    spdlog::register_logger(logger);
    return logger;
}

zk::log::log_wrapper::logger_ptr zk::log::log_wrapper::make_basic_file_logger(
    const std::string& logger_name,
    const filename_t& filepath,
    const std::string& pattern /*= "%8l | %Y-%m-%d %X.%f | %t | %s:%# | %v"*/,
    level_t filter_level /*= info*/,
    bool truncate /*= false*/)
{
    auto logger = spdlog::basic_logger_mt(logger_name, filepath, truncate);
    logger->set_level(filter_level);
    logger->set_pattern(pattern);
    spdlog::register_logger(logger);
    return logger;
}

